package com.qtyx.nms.mvp.presenter

import com.qtyx.nms.mvp.base.BaseObserver
import com.qtyx.nms.mvp.base.BasePresenter
import com.qtyx.nms.mvp.model.bean.LoginBean
import com.qtyx.nms.mvp.view.LoginView

/**
 * 登录
 */
class LoginPresenter(val view:LoginView) :BasePresenter() {

    /**
     * 登录
     */
    fun login(){
        val account=view.getAccount().text.toString()
        val password=view.getPassword().text.toString()

        if(account.isEmpty()){
            view.showVerifyHint(view.getAccount().hint as String)
            return
        }
        if(password.isEmpty()){
            view.showVerifyHint(view.getPassword().hint as String)
            return
        }

        val map=LinkedHashMap<String,String>()
        map["username"] = account
        map["password"] = password
        requestData(getApiServer().login("登录", map), object : BaseObserver<LoginBean>(view) {
            override fun onSuccess(data: LoginBean)= view.loginSucceed(data)
            override fun onError(msg: String)= view.onError(msg)
        })
    }
}